/********************************************************************************
 * Copyright(c) 2020-2025 BST All rights reserved.
 * - Filename
 * - Author
 * - Version V1.0.0
 * - Date    2025/04/08
 * - Brief
 * - FunctionList:
 ******************************************************************************
 * History:
 *
 *
 *
 ******************************************************************************
 */

#include "ConfigSingleton.hpp"

#include <fstream>
#include <iostream>

#include "nlohmann/json.hpp"

ConfigSingleton::ConfigSingleton() {}
ConfigSingleton::~ConfigSingleton() {}

ConfigSingleton &ConfigSingleton::get() {
  static ConfigSingleton instance;
  return instance;
}

void ConfigSingleton::loadConfig(const std::string &cfg) {
  nlohmann::json cfgJson;
  std::ifstream cfgFile(cfg);
  _type = 2;
  if (cfgFile.is_open()) {
    cfgFile >> cfgJson;
    auto mode = cfgJson.at("mode").get<std::string>();
    if (mode == "SingleFrame") {
      _type = 1;
    };
    _subIp = cfgJson.at("subIp").get<std::string>();
    _imagePath = cfgJson.at("imagePath").get<std::string>();
    _period = cfgJson.at("period").get<int>();
    if (_imagePath.back() != '/') {
      _imagePath.append("/");
    }
  }
  cfgFile.close();
}
std::string ConfigSingleton::getSubscribleIp() { return _subIp; }
std::string ConfigSingleton::getImagePath() { return _imagePath; }
int ConfigSingleton::getSendPeriod() { return _period; }
int ConfigSingleton::getReplayType() { return _type; }
